import { createSlice } from '@reduxjs/toolkit';

const loginSlice = createSlice({
	name: 'login',
	initialState: {
		url: '',
		username: '',
		password: '',
		org: '',
		token: '',
		refersh_ticket_time: 0,
		ticket: '',
		agentName: '',
		agentStatus: '',
		clientId: '',
		checkInGroups: []
	},
	reducers: {
		setLoginData(state, action) {
			return { ...state, ...action.payload };
		},

		setCheckInGroups(state, action) {
			let checkInGroups: any = action.payload;
			return { ...state, checkInGroups };
		},

		clearLoginData() {
			return {
				url: '',
				username: '',
				password: '',
				org: '',
				token: '',
				refersh_ticket_time: 0,
				ticket: '',
				agentName: '',
				agentStatus: '',
				clientId: '',
				checkInGroups: []
			};
		}
	}
});

export const { setLoginData, clearLoginData, setCheckInGroups } = loginSlice.actions;
export default loginSlice.reducer;
